FROM golang as build

ENV GOPROXY=https://goproxy.io
# ENV GOPROXY=https://mirrors.aliyun.com/goproxy/

ADD . /api

WORKDIR /api

# 交叉编译
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api_server

FROM alpine:3.7

ENV REDIS_ADDR=""
ENV REDIS_PW=""
ENV REDIS_DB=""
ENV MysqlDSN=""
ENV GIN_MODE="debug"
ENV PORT=3001
ENV OSS_END_POINT="inpm-images.oss-cn-shenzhen.aliyuncs.com"
ENV OSS_ACCESS_KEY_ID="LTAI4GCi4Qc3qTAuYc2txxFt"
ENV OSS_ACCESS_KEY_SECRET="G9FfizN4Aj2iaz9WPypIK0o7Pkvtjf"
ENV OSS_BUCKET="inpm-images"

RUN echo "http://mirrors.aliyun.com/alpine/v3.7/main/" > /etc/apk/repositories && \
    apk update && \
    apk add ca-certificates && \
    echo "hosts: files dns" > /etc/nsswitch.conf && \
    mkdir -p /www/conf

WORKDIR /www

COPY --from=build /api/api_server /usr/bin/api_server
ADD ./conf /www/conf

RUN chmod +x /usr/bin/api_server

ENTRYPOINT ["api_server"]